﻿Public Class frmQuanLiGiaoVien

    Private Sub frmQuanLiGiaoVien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim gvBUS As New GiaoVienBUS()
        Dim ds As List(Of GiaoVienDTO)
        ds = GiaoVienBUS.LayDSGiaoVien()

        dgvDSGV.Rows.Clear()
        For Each gv As GiaoVienDTO In ds
            dgvDSGV.Rows.Add(gv.MAGIAOVIEN, gv.TENGIAOVIEN, gv.GIOITINH, gv.NGAYSINH, gv.DIACHI, gv.SODT, gv.EMAIL, gv.MAMON)
        Next
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Try
            If (dgvDSGV.SelectedRows.Count > 0) Then
                Dim gvBUS As New GiaoVienBUS()
                Dim row As DataGridViewRow = dgvDSGV.SelectedRows(0)
                Dim maMON As Integer = Integer.Parse(row.Cells(0).Value)

                Dim frm As New frmSuaHoSoGiaoVien()
                'frm.MaHS = maHS
                frm.txtTenGV.Text = row.Cells(1).Value.ToString()
                If row.Cells(2).Value.ToString() = "Nam" Then
                    frm.rbNam.Checked = True
                Else
                    frm.rbNu.Checked = True
                End If
                frm.txtNgaySinh.Text = row.Cells(3).Value.ToString()
                frm.txtDiaChi.Text = row.Cells(4).Value.ToString()
                frm.txtSoDT.Text = row.Cells(5).Value.ToString()
                frm.txtEmail.Text = row.Cells(6).Value.ToString()
                frm.MaMon = maMON
                frm.ShowDialog()

                Dim ds As List(Of GiaoVienDTO)
                ds = GiaoVienBUS.LayDSGiaoVien()

                dgvDSGV.Rows.Clear()
                For Each gv As GiaoVienDTO In ds
                    dgvDSGV.Rows.Add(gv.MAGIAOVIEN, gv.TENGIAOVIEN, gv.GIOITINH, gv.NGAYSINH, gv.DIACHI, gv.SODT, gv.EMAIL, gv.MAMON)
                Next
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Try
            Dim hsBUS As New HocSinhBUS()
            If (dgvDSGV.SelectedRows.Count > 0) Then
                For Each row As DataGridViewRow In dgvDSGV.SelectedRows
                    Dim gvDAO As New GiaoVienDTO
                    gvDAO.MAGIAOVIEN = Integer.Parse(row.Cells(0).Value)
                    'hsDTO.MAHOCSINH =
                    GiaoVienBUS.XoaGiaoVien(gvDAO)
                Next
                MessageBox.Show("Xóa thành công")
                Dim ds As List(Of GiaoVienDTO)
                ds = GiaoVienBUS.LayDSGiaoVien()

                dgvDSGV.Rows.Clear()
                For Each gv As GiaoVienDTO In ds
                    dgvDSGV.Rows.Add(gv.MAGIAOVIEN, gv.TENGIAOVIEN, gv.GIOITINH, gv.NGAYSINH, gv.DIACHI, gv.SODT, gv.EMAIL, gv.MAMON)
                Next
            End If
        Catch ex As Exception
            'MessageBox.Show("Lỗi: " + ex.Message)
        End Try
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub
End Class